package com.example.project.controller;


import com.example.project.entity.Leaves;
import com.example.project.service.ILeavesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "请假信息表")
@RestController
public class LeavesController {
    @Autowired
    private ILeavesService leavesService;
    @CrossOrigin

    @ApiOperation(value = "对请假信息的添加")
    @GetMapping("getaddleaves")
    public int insert(Leaves leaves){
        System.out.println("进入增加请假信息方法");
        return leavesService.add(leaves);
    }

    @ApiOperation(value = "查询所有请假信息方法")
    @GetMapping("/getallleaves")
    public List<Leaves> getAllLeaves(Leaves leaves){
        System.out.println("进入查询所有请假信息的方法");
        List<Leaves> leavesList=leavesService.getAllLeaves(leaves);
        return leavesList;
    }

    @ApiOperation(value = "删除单条请假信息")
    @GetMapping("/deleteleaves")
    public int deleteLeaves(int id){
        System.out.println("进入请假信息删除方法");
        int returnValus=0;
        if(id!=0){
            Leaves leaves=new Leaves();
            leaves.setLeaveId(id);
            returnValus= leavesService.deleteLeaves(leaves);
        }
        return returnValus;
    }

    @ApiOperation(value = "对请假信息更新方法")
    @GetMapping("/updateLeaves")
    public int updateLeaves(Leaves leaves){
        System.out.println("进入请假信息更新方法");
        return leavesService.updateLeaves(leaves);
    }

    @ApiOperation(value = "获取单条请假数据")
    @GetMapping("/getoneLeaves")
    public Leaves getLeaves(int id){
        Leaves leaves=new Leaves();
        System.out.println("进入获取单条请假信息数据方法");
        if(id!=0){
            Leaves leaves1=new Leaves();
            leaves1.setLeaveId(id);
            leaves=leavesService.getLeaves(leaves1);
            System.out.println(""+leaves.getLeaveId());
        }
        return leaves;
    }
}
